import axios from 'axios'

import { getToken } from './token'

var instance = axios.create({
  baseURL: process.env.VUE_APP_URL
})

// 请求拦截器
instance.interceptors.request.use(
  function (config) {
    if (config.needToken === true) {
      const _token = getToken()
      if (_token) {
        config.headers.authorization = `Bearer ${_token}`
      }
    }
    return config
  },
  function (error) {
    return Promise.reject(error)
  }
)

export default instance
